package org.example.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.io.File;

@ConfigurationProperties(prefix = "hjh")
@Component
public class PropertiesConfig {
    // 加密的盐值,默认为123456  md5util
    private static String salt = "123456";
    // jwtutil
    private static Integer time = 60;
    private static String key = "123456";
    // upload
    private static String uploadDir;

    private static String accessPath;


    // get set
    public static String getSalt(){
        return salt;
    }
    public void setSalt(String salt){
        PropertiesConfig.salt = salt;
    }

    public static Integer getTime(){
        return time;
    }
    public void setTime(Integer time){
        PropertiesConfig.time = time;
    }
    public static String getKey(){
        return key;
    }
    public void setKey(String key){
        PropertiesConfig.key = key;
    }
    // 设置上传路径
    public void setUploadDir(String uploadDir){
        PropertiesConfig.uploadDir = uploadDir;
    }
    public static String getUploadDir(){
        return uploadDir;
    }
    public static String getUploadAvatarDir(){
        return PropertiesConfig.uploadDir+ File.separator+"avatar";
    }
    public static String getUploadFileDir(){
        return PropertiesConfig.uploadDir + File.separator+"file";
    }
    public static String getUploadCategoryDir(){
        return PropertiesConfig.getUploadDir()+ File.separator + "/category";
    }
    public static String getUploadTagDir(){
        return PropertiesConfig.getUploadDir() + File.separator + "tag";
    }

    public void setAccessPath(String accessPath){
        if (accessPath.charAt(accessPath.length() - 1) != '/' && accessPath.charAt(accessPath.length() - 1) != '\\' ){
            PropertiesConfig.accessPath = accessPath + "/";
        }else {
            PropertiesConfig.accessPath = accessPath;
        }
    }
    public static String getAccessPath(){
        return PropertiesConfig.accessPath;
    }
}
